package com.dm.learn_app_theme;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

public class MainActivity extends AppCompatActivity {
    private Context mContext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTheme(
                ThemeUtil.themeArr[SpUtil.getThemeIndex(this)][SpUtil.getNightModel(this) ? 1 : 0]
        );
        setContentView(R.layout.activity_main);
        this.mContext = this;
        findViewById(R.id.btn_1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SpUtil.setNightModel(mContext, !SpUtil.getNightModel(mContext));
                recreate();
            }
        });
    }

    /**
     * 不再使用
     */
    @Deprecated
    public void reload() {
        Intent intent = getIntent();
        overridePendingTransition(0, 0);
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        finish();
        overridePendingTransition(0, 0);
        startActivity(intent);
    }
}
